package com.xiaobai.service.user;

import com.xiaobai.dao.StudentUserDao;
import com.xiaobai.pojo.StudentUser;
import com.xiaobai.units.HttpUnits;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private StudentUserDao studentUserDao;

    @Override
    public String login(String student_name, String student_password) {

        //调用工具类的post方法
        String jsessionid=HttpUnits.loginPost(student_name,student_password);


        return jsessionid;
    }

    @Override
    public String getName(String jsessionid) {

        String url="https://jwxt.gdupt.edu.cn/xjkpxx!xjkpList.action";

        String result=HttpUnits.gyGet(url,jsessionid,null);

        Document document = Jsoup.parse(result);

        Elements elementsByClass = document.getElementsByClass("xjkp-table");

        String studentName = elementsByClass.select("label").eq(1).text();

//        int o=result.indexOf("姓名");
//
//        int p=result.indexOf("入学年份");
//
//        result=result.substring(o,p);

//        int endIndex=result.indexOf("</label>");

        return studentName;
    }

    @Override
    public boolean addStudentUser(StudentUser studentUser) {
        studentUserDao.insert(studentUser);
        return true;
    }

    @Override
    public String selectStudentPassword(String student_id) {
        return studentUserDao.selectStudentPassword(student_id);
    }


}
